define(['./../../initial'],
    function() {
        var app = angular.module('App.home');
        app.controller('user.passwordCtrl', ['$scope', '$rootScope', '$state', '$stateParams', 'User', 'showMsg',
            function($scope, $rootScope, $state, $stateParams, User, showMsg) {
                $scope.changePassword = function() {
                    if (!$scope.password || !$scope.newPassword1) {
                        showMsg('信息填写不完整', 'info');
                    } else if ($scope.newPassword1 !== $scope.newPassword2) {
                        showMsg('新密码填写不一致', 'info');
                    } else {
                        var user = new User();
                        user.postChangePassword({
                            password: $scope.password,
                            newPassword: $scope.newPassword1
                        }).then(function(data) {
                            if (data.toString() === 'true') {
                                showMsg('修改成功!', 'info');
                            } else {
                                showMsg('密码错误!', 'alert');
                            }
                        });
                    }
                };
            }
        ]);
    });
